<template>
  <div class="leftSidebar">
    <sidebar-item
      v-for="(data, index) in datas"
      :data="data"
      :index="index"
      :active-inx="selectIndex"
      @item-click="itemClick(index)"
    ></sidebar-item>
  </div>
</template>

<script>
import sidebarItem from "./sidebarItem";

export default {
  name: "leftSidebar",
  components: { sidebarItem },
  props: {
    datas: Array,
  },
  data: function () {
    return {
      selectIndex: 0,
    };
  },
  mounted: function () {
    for (let i = 0; i < this.datas.length; i++) {
      if (this.$route.path.indexOf(this.datas[i].path) != -1) {
        this.selectIndex = i;
        break;
      }
    }
  },
  methods: {
    itemClick: function (index) {
      if (index == this.selectIndex && this.$route.path == this.datas[index].path) {
        this.$emit("update-view");
      } else {
          if (this.datas[index].isKeepAlive){
              this.$router.push({name:this.datas[index].name,query:{t:new Date().getTime()}});
          }else {
              this.$router.push(this.datas[index].path);
          }

      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/components/leftSidebar.scss";
</style>
